/*
*首页js
* */
(function(){
    var Index={
        init:function(){
            this.Tab();
            this.scroll();
        },
        /*平台切换*/
        Tab:function(){
            $(".aside_show").eq(0).show();
            $(".banner_aside_tp a").each(function(index){
                $(this).on("mouseover",function(){
                    $(".aside_show").eq(index).show().siblings().hide();
                    $(this).addClass("active").siblings().removeClass("active");
                    $(".banner_aside_tp span").css("left",index*50+"%");
                });
            });
        },
        /*平台滚动*/
        scroll:function(){
            if($("#scroll_ul li").length<4){
                return;
            }
            var iH=$("#scroll_ul li").eq(0).height();
            $("#scroll_ul").timer=setInterval(function(){
                var _this=$("#scroll_ul");
                _this.animate({"top":-iH*4},700,function(){
                    for(var i=0;i<4;i++){
                        _this.find("li").first().appendTo(_this);
                    }
                    _this.css("top",0);
                });
            },4000);
        }
    };
    /*banner切换*/
    var banner={
        init:function(){
            this.picList=$(".scroll_pic li");
            this.smallBtnWrap=$(".small_btn");
            this.prevBtn=$(".banner_prev");
            this.nextBtn=$(".banner_next");
            this.iLen=this.picList.length;
            this.str="";
            this.n=0;
            this.timer=null;
            this.moveTime=600;
            this.delayTime=5000;
            this.picChange();
        },
        picChange:function(){
            if(this.picList.length>1){
                this.addSmallBtn();
                this.prevEvent();
                this.nextEvent();
                this.smallBtnEvent();
                this.setTime();
                this.clearTime();
            }
        },
        addSmallBtn:function(){
            var _this=this;
            this.picList.each(function(index){
                $(this).css("z-index",10-index);
                _this.str+='<a href="javascript:void(0);"></a>';
            });
            this.smallBtnWrap.append(_this.str);
            this.smallBtn=this.smallBtnWrap.find("a");
            this.smallBtn.first().addClass('active');
        },
        setTime:function(){
            var _this=this;
            this.timer=setInterval(function(){
                _this.n++;
                if(_this.n>_this.iLen-1){
                    _this.n=0;
                }
                _this.common();
            },this.delayTime);
        },
        clearTime:function(){
            this.baseHover(this.smallBtn,this)
            this.baseHover(this.prevBtn,this)
            this.baseHover(this.nextBtn,this)
        },
        baseHover:function(obj,that){
            obj.hover(function(){
                clearInterval(that.timer);
            },function(){
                that.setTime();
            });
        },
        prevEvent:function(){
            var _this=this;
            this.prevBtn.on("click",function(){
                _this.n--;
                if(_this.n<0){
                    _this.n=_this.iLen-1;
                }
                _this.common();
            });
        },
        nextEvent:function(){
            var _this=this;
            this.nextBtn.on("click",function(){
                _this.n++;
                if(_this.n>_this.iLen-1){
                    _this.n=0;
                }
                _this.common();
            });
        },
        smallBtnEvent:function(){
            var _this=this;
            this.smallBtn.each(function(index){
                $(this).on("mouseover",function(){
                    _this.n=index;
                    _this.common();
                });
            });
        },
        common:function(){
            var _this=this;
            var list=this.picList.eq(this.n).siblings();
            this.smallBtn.eq(this.n).addClass("active").siblings().removeClass("active");
            this.picList.eq(this.n).css("display","block");
            this.picList.eq(this.n).stop().animate({"opacity":1},this.moveTime);
            this.picList.eq(this.n).siblings().stop().animate({"opacity":0},this.moveTime,function(){
                list.css("display","none");
            });
        }
    };

    Index.init();
    banner.init();

})();

/*====================展会活动======================*/
(function(obj){
    function Init(obj1){
        this.oWrap=obj1.oWrap;
        this.oUl=obj1.oUl;
        this.pic=obj1.pic;
        this.txt=obj1.txt;
        this.btnwrap=obj1.btnwrap;
        this.prev=obj1.prev;
        this.next=obj1.next;
        this.base();
    }
    Init.prototype={
        constructor:Init,
        base:function(){
            this.str="";
            this.timer="";
            this.n=0;
            this.delayTime=4000;
            this.moveTime=400;
            this.iLen=this.pic.length;
            this.iW=this.pic.width();
            this.oUl.width(this.iLen*this.iW);   //获取ul的长度

        },
        scroll:function(){
            if(this.pic.length>1){
                this.addSmallBtn(this);
                this.smallBtnEvent(this);
                this.setTime(this);
                this.clearTime();
                this.showPrevNext(this);
                this.prevEvent(this);
            }
        },
        addSmallBtn:function(that){
            this.pic.each(function(){
                that.str+="<a href='javascript:void(0);'></a>";
            });

            this.btnwrap.html(that.str);
            this.smallBtn=this.btnwrap.find("a");
            this.smallBtn.first().addClass("active");
        },
        smallBtnEvent:function(that){
            this.smallBtn.each(function(index){
                $(this).on("mouseover",function(){

                    if(that.n>that.iLen-1){
                        that.pic.first().css({"left":0});
                        that.oUl.css("left",0);
                    }

                    if(that.n<0){
                        that.pic.last().css("left",0);
                        that.oUl.css("left",-that.iW*(that.iLen-1));
                    }

                    that.n=index;

                    that.common(that);
                });
            });
        },
        showPrevNext:function(that){
            this.oWrap.hover(function(){
                that.prev.css("opacity",1);
                that.next.css("opacity",1);
            },function(){
                that.prev.css("opacity",0);
                that.next.css("opacity",0);
            });

            this.nextEvent(this);
        },
        prevEvent:function(that){
            this.prev.on("click",function(){
                that.n--;

                if(that.n<that.iLen-1){
                    that.pic.first().css("left",0);
                }
                if(that.n==-1){
                    that.pic.last().css("left",-that.iLen*that.iW);
                }
                if(that.n==-2){
                    that.n=that.iLen-2;
                    that.pic.last().css("left",0);
                    that.oUl.css("left",-that.iW*(that.iLen-1));
                }
                that.common(that);
            });
        },
        nextEvent:function(that){
            this.next.on("click",function(){
                that.n++;
                that.moveRight();
            });
        },
        setTime:function(that){
            this.timer=setInterval(function(){
                that.n++;
                that.moveRight();
            },that.delayTime);
        },
        moveRight:function(){
            if(this.n>0){
                this.pic.last().css("left",0);
            }

            if(this.n==this.iLen){
                this.pic.first().css({"left":this.n*this.iW});
            }

            if(this.n==this.iLen+1){
                this.n=1;
                this.oUl.css("left",0);
                this.pic.first().css("left",0);
            }
            this.common(this);
        },
        common:function(that) {
            that.smallBtn.removeClass("active").eq(that.n%that.iLen).addClass("active");
            that.txt.hide().eq(that.n%that.iLen).show();
            that.oUl.stop(true).animate({'left': -that.iW * that.n}, that.moveTime, "easeInOutQuint");
        },
        clearTime:function(){
            this.hoverEvent(this.smallBtn,this);
            this.hoverEvent(this.prev,this);
            this.hoverEvent(this.next,this);
        },
        hoverEvent:function(obj,that){
            obj.hover(function(){
               clearInterval(that.timer);
            },function(){
                that.setTime(that);
            });

        }
    };

    new Init(obj).scroll();

})({
    oWrap:$(".i_news_pic"),
    oUl:$("#pic ul"),
    pic:$("#pic li"),
    txt:$("#txt p"),
    btnwrap:$(".i_news_pic .btn"),
    prev:$(".i_news_pic .prev"),
    next:$(".i_news_pic .next")
});





